#include <OgreConfigFile.h>
#include <OgreStringConverter.h>
#include <string>
#include "SettingsManager.h"

SettingsManager::SettingsManager()
{
    mDebugMode = true;
    mShowSettingsDialog = true;
    mSound = false;
	mDebugGeometry=true;
	mShowMenu=false;
}

void SettingsManager::parseSection(std::string sectionName)
{
    Ogre::String secName, typeName, typeValue;
    Ogre::ConfigFile cf;
    cf.load("cfg/settings.cfg");
    Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
    while (seci.hasMoreElements())
    {
        secName = seci.peekNextKey();
        Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
        Ogre::ConfigFile::SettingsMultiMap::iterator i;
        if (sectionName == secName)
        {
            for (i = settings->begin(); i != settings->end(); ++i)
            {
                typeName = i->first;
                typeValue = i->second;
                if (secName == "Bootstrap")
                {
                    if (typeName == "debug_mode")
                        mDebugMode = Ogre::StringConverter::parseBool(typeValue);
                    else if (typeName == "show_config_dialog")
                        mShowSettingsDialog = Ogre::StringConverter::parseBool(typeValue);
                    else if (typeName == "debug_geometry")
                        mDebugGeometry = Ogre::StringConverter::parseBool(typeValue);
                    else if (typeName == "show_menu")
                        mShowMenu = Ogre::StringConverter::parseBool(typeValue);
                }
                else if (secName == "General")
                {
                    if (typeName == "sound")
                    {
                        mSound = Ogre::StringConverter::parseBool(typeValue);
                    }
                }
            }
            break;
        }
    }
}
